package com.kaguya.factory;


/**
 * 抽象工厂模式，可以看做是对抽象工厂方法的抽象，抽象工厂适用于创建一个对象，抽象工厂模式适用于创建一群对象
 */
public class AbstractFactory {
    public static void main(String[] args) {
        AbstractFactories fac1 = new Fac01();
        fac1.createComputer();
        fac1.createPhone();

        AbstractFactories fac2 = new Fac02();
        fac2.createComputer();
        fac2.createPhone();
    }
}

abstract class AbstractFactories {
    /**
     模拟场景，现在工厂有两条流水线，一条是生产电脑，一条生产手机
     */
    abstract AbstractComputer createComputer();

    abstract AbstractPhone createPhone();
}

/**
 * 电脑抽象类
 */
abstract class AbstractComputer {
}

/**
 * 手机抽象类
 */
abstract class AbstractPhone {
}

/**
 * 电脑实现类
 */
class Computer1 extends AbstractComputer {

}

class Computer2 extends AbstractComputer {

}

/**
 * 手机实现类
 */
class Phone1 extends AbstractPhone {

}

class Phone2 extends AbstractPhone {

}

/**
 * 流水线1 抽象工厂实现类
 */
class Fac01 extends AbstractFactories {

    @Override
    AbstractComputer createComputer() {
        System.out.println("computer1 has been created");
        return new Computer1();
    }

    @Override
    AbstractPhone createPhone() {
        System.out.println("phone1 has been created");
        return new Phone1();
    }
}

/**
 * 流水线2 抽象工厂实现类
 */
class Fac02 extends AbstractFactories {

    @Override
    AbstractComputer createComputer() {
        System.out.println("computer2 has been created");
        return new Computer2();
    }

    @Override
    AbstractPhone createPhone() {
        System.out.println("phone2 has been created");
        return new Phone2();
    }
}
